package derivable;

import static util.Validator.nonEmpty;

/**
 * @author Henrik Wall
 * @author Rudolf Schmidt
 * @author Eugen Nemirowski
 */
public final class Variable {
	private final String name;

	private Variable(final String name) {
		this.name = name;
	}

	/**
	 * Creates a new {@link Variable}.
	 * 
	 * @param name the name of the variable (non-null)
	 * @return a new {@link Variable}
	 */
	public static Variable create(final String name) {
		return new Variable(nonEmpty(name, "name must not be empty"));
	}

	public String getName() {
		return name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + name.hashCode();
		return result;
	}

	@Override
	public boolean equals(final Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final Variable other = (Variable) obj;
		return name.equals(other.name);
	}

	@Override
	public String toString() {
		return name;
	}
}